import 'dart:convert';
import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
// import 'package:flutter_app/Xwidgets/cache_image.dart';
// import 'package:flutter_app/helper.dart';
// import 'package:flutter_app/router.dart';
// import 'package:flutter_app/views/mall_app/mall/recommended/hot_selling_goods/view.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:sp_util/sp_util.dart';
import 'package:yp/Xwidgets/bottom_sheet.dart';
import 'package:yp/Xwidgets/cache_image.dart';
import 'package:yp/config/config.dart';
import 'package:yp/helper.dart';
import 'package:yp/pages/mall_app/mall/recommended/hot_selling_goods/view.dart';
import 'package:yp/pages/trolley/trolley_logic.dart';
import 'package:yp/router.dart';
import 'dart:convert' as convert;
import 'package:fluwx/fluwx.dart' as fluwx;

import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:yp/services/api.dart';

import 'logic.dart';
import 'state.dart';

import 'package:intl/intl.dart';

class DecorationActivitiesPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _DecorationActivitiesPage();
  }
}

class _DecorationActivitiesPage extends State<DecorationActivitiesPage> {
  final DecorationActivitiesLogic logic = Get.put(DecorationActivitiesLogic());
  final DecorationActivitiesState state =
      Get.find<DecorationActivitiesLogic>().state;
  RxInt cartItemsNum = Get.put(TrolleyLogic()).cartItemsNum;
  @override
  Widget build(BuildContext context) {
    return GetBuilder<DecorationActivitiesLogic>(
      builder: (logic) {
        return Scaffold(
          appBar: AppBar(
            title: Text(
              state.titleString,
              style: TextStyle(
                color: Colors.black,
                fontSize: 17,
              ),
            ),
            centerTitle: true,
            elevation: 0,
            iconTheme: IconThemeData(
              color: Color(0xff333333),
            ),
            backgroundColor: Colors.white,
            actions: [
              IconButton(
                  icon: Icon(Icons.share),
                  color: Colors.black,
                  onPressed: () {
                    var model;
                    var shareUrl;

                    shareUrl = Config.H5_URL + '&isGOActivity=true&tmplId=' + state.tmpl_id.toString() + '&currentShopId=' + state.currentShopId.toString();

                    print('分享路径');
                    print(state.image_id);

                    YpBottomSheet.showShareGift(context,
                        (selectIndex, selectString, {info, list}) {
                      print(state.image_id);
                      model = fluwx.WeChatShareWebPageModel(
                        shareUrl,
                        description: state.tmpl_desc,
                        title: state.titleString,
                        thumbnail: state.image_id != null&&state.image_id != ''?fluwx.WeChatImage.network(state.image_id): fluwx.WeChatImage.asset(
                          'assets/images/defaultAvatar_image.png',
                        ),
                        scene: selectIndex == 0
                            ? fluwx.WeChatScene.SESSION
                            : fluwx.WeChatScene.TIMELINE,
                      );

                      fluwx.shareToWeChat(model);
                    }, title: '活动');
                  })
            ],
          ),
          body: GetBuilder<DecorationActivitiesLogic>(
            builder: (logic) {
              return
                  //通过ConstrainedBox来确保Stack占满屏幕
                  ConstrainedBox(
                      constraints: BoxConstraints.expand(),
                      child: Stack(
                          alignment: Alignment.center, //指定未定位或部分定位widget的对齐方式
                          children: <Widget>[
                            Container(
                              color: Color(0xffEFF0F3),
                              child: SmartRefresher(
                                controller: state.refreshController,
                                header: CustomHeader(
                                  builder: (BuildContext context,
                                      RefreshStatus mode) {
                                    Widget body;
                                    if (mode == RefreshStatus.completed) {
                                      body = CupertinoActivityIndicator();
                                    }
                                    return Container(
                                      height: 55.0,
                                      child: Center(child: body),
                                    );
                                  },
                                ),
                                // footer: CustomFooter(
                                //   builder: (BuildContext context, LoadStatus mode) {
                                //     Widget body;
                                //     if (mode == LoadStatus.idle) {
                                //       body = Text("没有更多数据了");
                                //     } else if (mode == LoadStatus.loading) {
                                //       body = CupertinoActivityIndicator();
                                //     } else if (mode == LoadStatus.failed) {
                                //       body = Text("刷新失败");
                                //     } else {
                                //       body = Text("没有更多数据了");
                                //     }
                                //     return Container(
                                //       height: 55.0,
                                //       child: Center(child: body),
                                //     );
                                //   },
                                // ),
                                // enablePullUp: true,
                                enablePullDown: true,
                                onRefresh: logic.refreshData,
                                // onLoading: logic.loadMoreData,
                                child: ListView(
                                  padding: EdgeInsets.zero,
                                  children: state.templateList.map((itemModel) {
                                    return _itemWidget(dataMap: itemModel);
                                  }).toList(),
                                ),
                              ),
                            ),
                            Positioned(
                              left: 18.0,
                              bottom: 30,
                              child: GestureDetector(
                                onTap: () {
                                  print('跳转购物车 点击事件！！！');
                                  // if (kIsWeb) {
                                  //   //downloadOrGoToApp();
                                  // } else {
                                  //   if (SpUtil.getString('token') == null ||
                                  //       SpUtil.getString('token').isEmpty) {
                                  //     Get.toNamed(RouteConfig.mallLogin, arguments: {
                                  //       'itemNumId': logic.itemNumId,
                                  //       'styleNumId': logic.styleNumId,
                                  //       'shopId': logic.shopId,
                                  //       'typeIndex': state.typeIndex,
                                  //     }).then((value) {
                                  //       if (SpUtil.getString('token') != null &&
                                  //           SpUtil.getString('token').isNotEmpty) {
                                  //         logic.requestDetail();
                                  //       }
                                  //     });
                                  //   } else {
                                  Get.offAllNamed(RouteConfig.main,
                                      arguments: {'shoppingCart': '2'});
                                  //   }
                                  // }
                                },
                                behavior: HitTestBehavior.opaque,
                                child: Stack(
                                  alignment: Alignment.center,
                                  children: [
                                    Opacity(
                                      opacity: 0.7,
                                      child: Container(
                                          width: 120.w,
                                          height: 120.w,
                                          decoration: BoxDecoration(
                                            color: Colors.white,
                                            borderRadius:
                                                BorderRadius.circular(60.w),
                                            // border:Border.all(width: 1,color:Colors.grey , style: BorderStyle.solid),
                                          )),
                                      //     CircleAvatar(
                                      //       radius: 50.w,
                                      // backgroundColor:Colors.white ,),
                                    ),
                                    Align(
                                      alignment: Alignment.center,
                                      child: new Image.asset(
                                        'assets/images/shopping_car_9.png',
                                        width: 52.w,
                                        height: 58.w,
                                      ),
                                    ),
                                    cartItemsNum != null &&
                                            cartItemsNum.value != null &&
                                            cartItemsNum.value > 0
                                        ? Positioned(
                                            right: 5.0,
                                            top: 5.0,
                                            child: angleMark(
                                                cartItemsNum.value.toString()),
                                          )
                                        : Container(),
                                  ],
                                ),
                              ),
                            ),
                            Positioned(
                              right: 18.0,
                              bottom: 200.w,
                              child: GestureDetector(
                                onTap: () {
                                 gotoHelpDesk();
                                },
                                behavior: HitTestBehavior.opaque,
                                child: Stack(
                                  alignment: Alignment.center,
                                  children: [
                                    Opacity(
                                      opacity: 0.7,
                                      child: Container(
                                          width: 120.w,
                                          height: 120.w,
                                          decoration: BoxDecoration(
                                            color: Colors.white,
                                            borderRadius:
                                                BorderRadius.circular(60.w),
                                            // border:Border.all(width: 1,color:Colors.grey , style: BorderStyle.solid),
                                          )),
                                      //     CircleAvatar(
                                      //       radius: 50.w,
                                      // backgroundColor:Colors.white ,),
                                    ),
                                    Align(
                                      alignment: Alignment.center,
                                      child: Column(children: [
                                        Image.asset(
                                          'assets/images/kefu1.png',
                                          width: 64.w,
                                          height: 64.w,
                                        ),
                                        Opacity(
                                          opacity: 0.5,
                                          child: Text('客服'),
                                        ),
                                      ]),
                                    ),
                                  ],
                                ),
                              ),
                            ),
                            Positioned(
                              right: 18.0,
                              bottom: 50.w,
                              child: GestureDetector(
                                onTap: () {
                                  Get.offAllNamed(RouteConfig.main);
                                },
                                behavior: HitTestBehavior.opaque,
                                child: Stack(
                                  alignment: Alignment.center,
                                  children: [
                                    Opacity(
                                      opacity: 0.7,
                                      child: Container(
                                          width: 120.w,
                                          height: 120.w,
                                          decoration: BoxDecoration(
                                            color: Colors.white,
                                            borderRadius:
                                                BorderRadius.circular(60.w),
                                            // border:Border.all(width: 1,color:Colors.grey , style: BorderStyle.solid),
                                          )),
                                      //     CircleAvatar(
                                      //       radius: 50.w,
                                      // backgroundColor:Colors.white ,),
                                    ),
                                    Align(
                                      alignment: Alignment.center,
                                      child: Column(children: [
                                        Image.asset(
                                          'assets/images/store.png',
                                          width: 50.w,
                                          height: 50.w,
                                        ),
                                        Opacity(
                                          opacity: 0.5,
                                          child: Text('商城'),
                                        ),
                                      ]),
                                    ),
                                  ],
                                ),
                              ),
                            ),
                          ]));
            },
          ),
        );
      },
    );
  }
  gotoHelpDesk() {
    if (SpUtil.getString('token') == null ||
        SpUtil.getString('token').isEmpty) {
      Get.toNamed(RouteConfig.mallLogin,
      ).then((value) {
        if (SpUtil.getString('token') != null &&
            SpUtil.getString('token').isNotEmpty) {

        }
      });
    } else {
      if (state.keFuString.isNotEmpty) {
        var otherParams = {
          "productInfo": {},
          // "peerId": "10052439",
          "nickName": "${SpUtil.getString('empeName')}",
        };
        var clientId = '${SpUtil.getInt('empeNumId')}';
        var kefubaseUrl =
            'https://7moor.zrhsh.com/wapchat.html?fromUrl=&urlTitle=&language=ZHCN';
        kefubaseUrl = kefubaseUrl +
            '&accessId=' +
            state.keFuString +
            '&otherParams=' +
            jsonEncode(otherParams) +
            '&clientId=' +
            clientId;

        Get.toNamed(RouteConfig.webview, arguments: {
          "url":
          kefubaseUrl,
        });
      }
    }
  }
  Widget angleMark(String cartItemsNum) {
    return Align(
      alignment: Alignment.topRight,
      child: Container(
        width: cartItemsNum.length >= 3 ? 21 : 18,
        height: cartItemsNum.length >= 3 ? 21 : 18,
        decoration: BoxDecoration(
          color: Color(0xffff322e),
          shape: BoxShape.circle,
        ),
        alignment: Alignment.center,
        child: Text(
          cartItemsNum,
          style: TextStyle(
            color: Color(0xffffffff),
            fontSize: 11,
          ),
        ),
      ),
    );
  }

  // item
  Widget _itemWidget({
    Map<String, dynamic> dataMap,
  }) {
    if (dataMap['widgets_sign'] == 1) {
      //组件类型 1 轮播图，2 快捷导航，3 拼图，4 商品展示，9 图片热区，11跑马灯
      return _bannerWidget(dataMap: dataMap);
    } else if (dataMap['widgets_sign'] == 4) {
      List list = [];
      state.goodsList.map((e) {
        if (e['widgets_data_id'] == dataMap['widgets_data_id']) {
          list = e['listMap'];
        }
      }).toList();
      List list1 = [];
      state.angleInformationList.forEach((e) {
        if (e['widgets_data_id'] == dataMap['widgets_data_id']) {
          list1 = e['listMap'];
        }
      });
      var map = convert.jsonDecode(dataMap['widgets_data_params']);
      var _pageSize = 12;
      if (map['nublayout'] != 'no' &&
          map['nubnub'] != null &&
          map['nubnub'] != '') {
        _pageSize = int.parse(map['nubnub']);
      }
      return HotSellingGoodsPage(
        map: dataMap,
        goodsList: list,
        angleInformationList: list1,
        perPageSize: _pageSize,
        haha222: 0,
      );
    } else if (dataMap['widgets_sign'] == 2) {
      return _entranceWidget(dataMap: dataMap);
    } else if (dataMap['widgets_sign'] == 3) {
      return _hottestCommodityWidget(dataMap: dataMap);
    } else if (dataMap['widgets_sign'] == 9) {
      bool _show = true;
      DateTime _now = DateTime.now();
      if (dataMap['widgets_data_begin_time'] != null) {
        DateTime _d = DateTime.parse(dataMap['widgets_data_begin_time']);
        if (_d.isBefore(_now)) {
        } else {
          _show = false;
        }
      }
      if (dataMap['widgets_data_end_time'] != null) {
        DateTime _d = DateTime.parse(dataMap['widgets_data_end_time']);
        if (_d.isAfter(_now)) {
        } else {
          _show = false;
        }
      }
      if (_show == true) {
        return _imageHotZone(dataMap: dataMap);
      } else {
        return Container();
      }
    } else if (dataMap['widgets_sign'] == 8) {
      if (state == null || state.couponsList == null) return Row();
      // print('=================优惠券===============  dataMap = $dataMap');
      var map = convert.jsonDecode(dataMap['widgets_data_params']);
      // print('+++++++++++++++++++++++++++++++ map = $map');

      List list = [];
      state.couponsList.forEach((element) {
        if (element['widgets_data_id'] == dataMap['widgets_data_id']) {
          list = element['listMap'];
        }
      });

      var params = jsonDecode(dataMap['widgets_data_params']);
      print("tmpl.=${params}");
      return Container(
        color: Colors.white,
        margin: EdgeInsets.only(top: 15),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            if (dataMap['widgets_title'] != null &&
                dataMap['widgets_title'] != '')
              Padding(
                padding: const EdgeInsets.only(left: 15, top: 15),
                child: Text(
                  "${dataMap['widgets_title']}",
                  style: TextStyle(fontSize: 18),
                ),
              ),
            _discountCouponWidget(
              couponList: list,
              col: map["select_coupon"],
              params: params,
            ),
          ],
        ),
      );
    }
    return Container(
      height: 10,
      color: Colors.transparent,
    );
  }

  // 图片热区
  Widget _imageHotZone({
    Map<String, dynamic> dataMap,
  }) {
    var imageHotZoneMap = convert.jsonDecode(dataMap['widgets_data_params']);
    List hotList = imageHotZoneMap['hotList'];
    List<Widget> stackArray = [
      cacheImage(
        imageUrl: '${imageHotZoneMap['pic_url']}',
        width: MediaQuery.of(context).size.width,
        fit: BoxFit.fitWidth,
      ),
    ];
    hotList.map((e) {
      stackArray.add(
        Positioned(
          left: setWidth(double.parse(e['left'].toString())),
          top: setWidth(double.parse(e['top'].toString())),
          right: setWidth(double.parse(e['radio'].toString())),
          child: InkWell(
            onTap: () {
              Map<String, dynamic> map = {
                'linktype': e['targetType'].toString(),
                'linktarget': e['targetPage'].toString(),
                'shop_id': e['shop_id'].toString(),
              };
              umpDeco(
                url: e['targetType'].toString(),
                model: map,
              );
            },
            child: Container(
              width: setWidth(double.parse(e['width'].toString())),
              height: setWidth(double.parse(e['height'].toString())),
            ),
          ),
        ),
      );
    }).toList();

    return Container(
      color: Colors.red,
      margin: EdgeInsets.only(
        top: setWidth(20),
      ),
      child: Column(
        children: [
          Offstage(
            offstage: dataMap['widgets_data_show_title'] == 0,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Row(
                      children: [
                        Padding(
                          padding: EdgeInsets.only(
                            left: setWidth(16),
                            top: setWidth(20),
                            right: setWidth(12),
                            bottom: setWidth(16),
                          ),
                          child: Container(
                            decoration: BoxDecoration(
                              color: Color(0xffea5504),
                              borderRadius: BorderRadius.circular(setWidth(3)),
                            ),
                            width: setWidth(6),
                            height: setWidth(32),
                          ),
                        ),
                        Text.rich(
                          TextSpan(
                            children: [
                              TextSpan(
                                text: dataMap['widgets_data_title'],
                                style: TextStyle(
                                  color: Color(0xff333333),
                                  fontSize: 15,
                                ),
                              ),
                              WidgetSpan(
                                child: SizedBox(width: 4),
                              ),
                              TextSpan(
                                text: dataMap['widgets_data_sub_title'],
                                style: TextStyle(
                                  color: Colors.black.withOpacity(0.3),
                                  fontSize: 12,
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                    Offstage(
                      offstage: dataMap['widgets_data_show_more'] == 0,
                      child: Row(
                        children: [
                          InkWell(
                            onTap: () {
                              print(' 更多按钮点击事件 商品 横排  ');
                            },
                            child: Container(
                              height: setWidth(60),
                              width: setWidth(80),
                              alignment: Alignment.centerRight,
                              child: Text(
                                '更多',
                                style: TextStyle(
                                  color: Color(0xff999999),
                                  fontSize: 12,
                                ),
                              ),
                            ),
                          ),
                          SizedBox(
                            width: setWidth(20),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
                Divider(
                  height: setWidth(4),
                  color: Color(0xffefefef),
                ),
              ],
            ),
          ),
          Stack(
            children: stackArray,
          ),
        ],
      ),
    );
  }

  // 轮播图
  Widget _bannerWidget({
    Map<String, dynamic> dataMap,
  }) {
    var bannerMap = convert.jsonDecode(dataMap['widgets_data_params']);
    double ratio, height;
    if (bannerMap['ratio'] == null || bannerMap['ratio'] == '') {
      if (bannerMap['height'] == null || bannerMap['height'] == '') {
        height = 220;
      } else {
        height = double.parse(bannerMap['height'].toString());
      }
    } else {
      ratio = double.parse(bannerMap['ratio'].toString());
      height = (MediaQuery.of(context).size.width - 20) / ratio;
    }
    height = height + 20;
    List bannerList = bannerMap['pictures'];

    DateTime currentTime = DateTime.now();
    DateTime beginTime;
    DateTime endTime;
    List listBannerMap = [];
    for (int i = 0; i < bannerList.length; i++) {
      var map = bannerList[i];
      String begin_time = map['begin_time'] ?? '';
      String end_time = map['end_time'] ?? '';
      if (begin_time != '' && end_time != '') {
        beginTime = DateTime.parse('${map['begin_time']}');
        endTime = DateTime.parse('${map['end_time']}');
        if (currentTime.isAfter(beginTime) && currentTime.isBefore(endTime)) {
          listBannerMap.add(map);
        }
      } else if (begin_time != '' && end_time == '') {
        beginTime = DateTime.parse('${map['begin_time']}');
        if (currentTime.isAfter(beginTime)) {
          listBannerMap.add(map);
        }
      } else if (begin_time == '' && end_time != '') {
        endTime = DateTime.parse('${map['end_time']}');
        if (currentTime.isBefore(endTime)) {
          listBannerMap.add(map);
        }
      } else {
        listBannerMap.add(map);
      }
    }

    return Container(
      padding: EdgeInsets.symmetric(horizontal: setWidth(20)),
      child: Column(
        children: [
          Offstage(
            offstage: dataMap['widgets_data_show_title'] ==
                0, // widgets_data_show_title   0 不展示  1 展示
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.end,
              children: [
                Row(
                  crossAxisAlignment: CrossAxisAlignment.end,
                  children: [
                    Container(
                      width: 2,
                      height: 20,
                      color: Colors.red,
                    ),
                    SizedBox(
                      width: 4,
                    ),
                    Text(
                      dataMap['widgets_data_title'],
                      style: TextStyle(
                        color: Colors.black,
                        fontSize: 18,
                      ),
                    ),
                    SizedBox(
                      width: 4,
                    ),
                    Text(
                      dataMap['widgets_data_sub_title'],
                      style: TextStyle(
                        color: Colors.black.withOpacity(0.3),
                        fontSize: 13,
                      ),
                    ),
                  ],
                ),
                Offstage(
                  offstage: dataMap['widgets_data_show_more'] ==
                      0, // widgets_data_show_more 0 不显示 1 显示
                  child: InkWell(
                    onTap: () {
                      print(' 更多点击事件 ！！！！ ');
                    },
                    child: Text(
                      '更多',
                      style: TextStyle(
                        color: Color(0xffaaaaaa),
                        fontSize: 13,
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
          Container(
            height: setWidth(height * 2),
            padding: EdgeInsets.only(
              top: setWidth(20),
              bottom: setWidth(20),
            ),
            child: Swiper(
              key: ValueKey('${listBannerMap.length.toString()}'),
              autoplay: true,
              onTap: (int index) {
                print('++++ onTap ++++ 点击事件！！！');
                Map map = listBannerMap[index];
                umpDeco(
                  url: map['linktype'].toString(),
                  model: map,
                );
              },
              itemCount: listBannerMap.length,
              itemBuilder: (BuildContext context, int index) {
                return Container(
                  child: ClipRRect(
                    borderRadius: BorderRadius.circular(setWidth(10)),
                    child: CachedImage(
                      width: MediaQuery.of(context).size.width - 20,
                      height: setWidth((height - 20) * 2),
                      margin: EdgeInsets.zero,
                      scale: BoxFit.fill,
                      path: listBannerMap[index]['pic_url'],
                    ),
                  ),
                );
              },
              pagination: SwiperPagination(),
            ),
          ),
        ],
      ),
    );
  }

  // 九宫格
  Widget _entranceWidget({
    Map<String, dynamic> dataMap,
  }) {
    int countInt = 0; // 每行显示数量   item数量 小于等于8 每行4 个    大于8 每行5个
    var bannerMap = convert.jsonDecode(dataMap['widgets_data_params']);
    Color titleColor = Color(0xff222222);
    if (bannerMap['color'] != null && bannerMap['color'] != '') {
      titleColor = getColorFromHex('${bannerMap['color']}');
    }
    List entranceList = bannerMap['navs'];
    countInt = entranceList.length > 8 ? 5 : 4;

    _itemWidget({
      Map<String, dynamic> map,
    }) {
      return InkWell(
        onTap: () {
          umpDeco(
            url: map['linktype'].toString(),
            model: map,
          );
        },
        child: Container(
          width: countInt == 5 ? setWidth(142) : setWidth(177.5),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              map['pic_url'] != ''
                  ? CachedImage(
                      path: map['pic_url'],
                      width: setWidth(90),
                      height: setWidth(90),
                      scale: BoxFit.contain,
                    )
                  : ClipOval(
                      child: Container(
                        color: Color(0xffaaaaaa),
                        width: setWidth(90),
                        height: setWidth(90),
                      ),
                    ),
              SizedBox(
                height: setWidth(10),
              ),
              Text(
                map['icon_name'],
                style: TextStyle(
                  color: titleColor,
                  fontSize: 13,
                ),
              ),
              SizedBox(
                height: setWidth(10),
              ),
            ],
          ),
        ),
      );
    }

    return Container(
      color: Color(0xffEFF0F3),
      padding: EdgeInsets.symmetric(horizontal: setWidth(20)),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Offstage(
            offstage: dataMap['widgets_data_show_title'] == 0,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Row(
                      children: [
                        Padding(
                          padding: EdgeInsets.only(
                            left: setWidth(16),
                            top: setWidth(20),
                            right: setWidth(12),
                            bottom: setWidth(16),
                          ),
                          child: Container(
                            decoration: BoxDecoration(
                              color: Color(0xffea5504),
                              borderRadius: BorderRadius.circular(setWidth(3)),
                            ),
                            width: setWidth(6),
                            height: setWidth(32),
                          ),
                        ),
                        Text.rich(
                          TextSpan(
                            children: [
                              TextSpan(
                                text: dataMap['widgets_data_title'],
                                style: TextStyle(
                                  color: Color(0xff333333),
                                  fontSize: 15,
                                ),
                              ),
                              WidgetSpan(
                                child: SizedBox(width: 4),
                              ),
                              TextSpan(
                                text: dataMap['widgets_data_sub_title'],
                                style: TextStyle(
                                  color: Colors.black.withOpacity(0.3),
                                  fontSize: 12,
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                    Offstage(
                      offstage: dataMap['widgets_data_show_more'] == 0,
                      child: Row(
                        children: [
                          InkWell(
                            onTap: () {
                              print(' 更多按钮点击事件 商品 横排  ');
                            },
                            child: Container(
                              height: setWidth(60),
                              width: setWidth(80),
                              alignment: Alignment.centerRight,
                              child: Text(
                                '更多',
                                style: TextStyle(
                                  color: Color(0xff999999),
                                  fontSize: 12,
                                ),
                              ),
                            ),
                          ),
                          SizedBox(
                            width: setWidth(20),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
                Divider(
                  height: setWidth(4),
                  color: Color(0xffefefef),
                ),
              ],
            ),
          ),
          Wrap(
            direction: Axis.horizontal,
            runSpacing: setWidth(20), // 排间距
            children: entranceList.map((e) {
              return _itemWidget(map: e);
            }).toList(),
          ),
        ],
      ),
    );
  }

  // 最热单品
  Widget _hottestCommodityWidget({
    Map<String, dynamic> dataMap,
  }) {
    //widgets_data_params
    var hottestMap = convert.jsonDecode(dataMap['widgets_data_params']);
    int countInt = hottestMap['styletag']; // 显示几张图片
    List imageArray = hottestMap['pictures']; // 图片数组

    return Container(
      color: Colors.white,
      child: Column(
        children: [
          Offstage(
            offstage: dataMap['widgets_data_show_title'] == 0,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Row(
                      children: [
                        Padding(
                          padding: EdgeInsets.only(
                            left: setWidth(16),
                            top: setWidth(20),
                            right: setWidth(12),
                            bottom: setWidth(16),
                          ),
                          child: Container(
                            decoration: BoxDecoration(
                              color: Color(0xffea5504),
                              borderRadius: BorderRadius.circular(setWidth(3)),
                            ),
                            width: setWidth(6),
                            height: setWidth(32),
                          ),
                        ),
                        Text.rich(
                          TextSpan(
                            children: [
                              TextSpan(
                                text: dataMap['widgets_data_title'],
                                style: TextStyle(
                                  color: Color(0xff333333),
                                  fontSize: 15,
                                ),
                              ),
                              WidgetSpan(
                                child: SizedBox(width: 4),
                              ),
                              TextSpan(
                                text: dataMap['widgets_data_sub_title'],
                                style: TextStyle(
                                  color: Colors.black.withOpacity(0.3),
                                  fontSize: 12,
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                    Offstage(
                      offstage: dataMap['widgets_data_show_more'] == 0,
                      child: Row(
                        children: [
                          InkWell(
                            onTap: () {
                              print(' 更多按钮点击事件 商品 横排  ');
                            },
                            child: Container(
                              height: setWidth(60),
                              width: setWidth(80),
                              alignment: Alignment.centerRight,
                              child: Text(
                                '更多',
                                style: TextStyle(
                                  color: Color(0xff999999),
                                  fontSize: 12,
                                ),
                              ),
                            ),
                          ),
                          SizedBox(
                            width: setWidth(20),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
                Divider(
                  height: setWidth(4),
                  color: Color(0xffefefef),
                ),
              ],
            ),
          ),
          countInt == 4
              ? Container(
                  padding: EdgeInsets.only(
                    top: setWidth(26),
                    bottom: setWidth(26),
                  ),
                  child: Padding(
                    padding: EdgeInsets.symmetric(horizontal: setWidth(20)),
                    child: Row(
                      children: [
                        imageArray.length >= 1
                            ? InkWell(
                                onTap: () {
                                  Map map = imageArray[0];
                                  umpDeco(
                                    url: map['linktype'].toString(),
                                    model: map,
                                  );
                                },
                                child: CachedImage(
                                  path: imageArray[0]['pic_url'],
                                  width: setWidth(296),
                                  height: setWidth(410),
                                  scale: BoxFit.fill,
                                ),
                              )
                            : Container(
                                width: setWidth(296),
                                height: setWidth(410),
                              ),
                        SizedBox(
                          width: setWidth(14),
                        ),
                        Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            imageArray.length >= 2
                                ? InkWell(
                                    onTap: () {
                                      Map map = imageArray[1];
                                      umpDeco(
                                        url: map['linktype'].toString(),
                                        model: map,
                                      );
                                    },
                                    child: CachedImage(
                                      path: imageArray[1]['pic_url'],
                                      width: setWidth(390),
                                      height: setWidth(196),
                                      scale: BoxFit.fill,
                                    ),
                                  )
                                : Container(
                                    width: setWidth(390),
                                    height: setWidth(196),
                                  ),
                            SizedBox(
                              height: setWidth(8),
                            ),
                            Row(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                imageArray.length >= 3
                                    ? InkWell(
                                        onTap: () {
                                          Map map = imageArray[2];
                                          umpDeco(
                                            url: map['linktype'].toString(),
                                            model: map,
                                          );
                                        },
                                        child: CachedImage(
                                          path: imageArray[2]['pic_url'],
                                          width: setWidth(190),
                                          height: setWidth(200),
                                          scale: BoxFit.fill,
                                        ),
                                      )
                                    : Container(
                                        width: setWidth(190),
                                        height: setWidth(200),
                                      ),
                                SizedBox(
                                  width: setWidth(8),
                                ),
                                imageArray.length >= 4
                                    ? InkWell(
                                        onTap: () {
                                          Map map = imageArray[3];
                                          umpDeco(
                                            url: map['linktype'].toString(),
                                            model: map,
                                          );
                                        },
                                        child: CachedImage(
                                          path: imageArray[3]['pic_url'],
                                          width: setWidth(190),
                                          height: setWidth(200),
                                          scale: BoxFit.fill,
                                        ),
                                      )
                                    : Container(
                                        width: setWidth(190),
                                        height: setWidth(200),
                                      ),
                              ],
                            ),
                          ],
                        ),
                      ],
                    ),
                  ),
                )
              : countInt == 2
                  ? Container(
                      padding: EdgeInsets.symmetric(
                          horizontal: setWidth(20), vertical: setWidth(26)),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          imageArray.length >= 1
                              ? InkWell(
                                  onTap: () {
                                    Map map = imageArray[0];
                                    umpDeco(
                                      url: map['linktype'].toString(),
                                      model: map,
                                    );
                                  },
                                  child: CachedImage(
                                    path: imageArray[0]['pic_url'],
                                    width: setWidth(345),
                                    height: setWidth(345),
                                    scale: BoxFit.fill,
                                  ),
                                )
                              : Container(
                                  width: setWidth(345),
                                  height: setWidth(345),
                                  color: Colors.yellow,
                                ),
                          imageArray.length >= 2
                              ? InkWell(
                                  onTap: () {
                                    Map map = imageArray[1];
                                    umpDeco(
                                      url: map['linktype'].toString(),
                                      model: map,
                                    );
                                  },
                                  child: CachedImage(
                                    path: imageArray[1]['pic_url'],
                                    width: setWidth(345),
                                    height: setWidth(345),
                                    scale: BoxFit.fill,
                                  ),
                                )
                              : Container(
                                  width: setWidth(345),
                                  height: setWidth(345),
                                  // color: Colors.red,
                                ),
                        ],
                      ),
                    )
                  : countInt == 3
                      ? Container(
                          padding: EdgeInsets.symmetric(
                              horizontal: setWidth(20), vertical: setWidth(26)),
                          child: Row(
                            children: [
                              imageArray.length >= 1
                                  ? InkWell(
                                      onTap: () {
                                        Map map = imageArray[0];
                                        umpDeco(
                                          url: map['linktype'].toString(),
                                          model: map,
                                        );
                                      },
                                      child: CachedImage(
                                        path: imageArray[0]['pic_url'],
                                        width: setWidth(296),
                                        height: setWidth(410),
                                        scale: BoxFit.fill,
                                      ),
                                    )
                                  : Container(
                                      width: setWidth(296),
                                      height: setWidth(410),
                                    ),
                              SizedBox(
                                width: setWidth(14),
                              ),
                              Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  imageArray.length >= 2
                                      ? InkWell(
                                          onTap: () {
                                            Map map = imageArray[1];
                                            umpDeco(
                                              url: map['linktype'].toString(),
                                              model: map,
                                            );
                                          },
                                          child: CachedImage(
                                            path: imageArray[1]['pic_url'],
                                            width: setWidth(390),
                                            height: setWidth(196),
                                            scale: BoxFit.fill,
                                          ),
                                        )
                                      : Container(
                                          width: setWidth(390),
                                          height: setWidth(196),
                                        ),
                                  SizedBox(
                                    height: setWidth(8),
                                  ),
                                  imageArray.length >= 3
                                      ? InkWell(
                                          onTap: () {
                                            Map map = imageArray[2];
                                            umpDeco(
                                              url: map['linktype'].toString(),
                                              model: map,
                                            );
                                          },
                                          child: CachedImage(
                                            path: imageArray[2]['pic_url'],
                                            width: setWidth(390),
                                            height: setWidth(196),
                                            scale: BoxFit.fill,
                                          ),
                                        )
                                      : Container(
                                          width: setWidth(390),
                                          height: setWidth(196),
                                        ),
                                ],
                              ),
                            ],
                          ),
                        )
                      : Container(
                          padding: EdgeInsets.symmetric(
                              horizontal: setWidth(20), vertical: setWidth(26)),
                          child: imageArray.length >= 1
                              ? InkWell(
                                  onTap: () {
                                    Map map = imageArray[0];
                                    umpDeco(
                                      url: map['linktype'].toString(),
                                      model: map,
                                    );
                                  },
                                  child: cacheImage(
                                    imageUrl: imageArray[0]['pic_url'],
                                    width: setWidth(710),
                                    fit: BoxFit.fitWidth,
                                  ),
                                )
                              : Container(),
                        ),
        ],
      ),
    );

    // 下面是 跑马灯信息
    /*
                SizedBox(
                  height: setWidth(4),
                ),
                Container(
                  height: setWidth(90),
                  width: setWidth(750),
                  decoration: BoxDecoration(
                    color: Colors.white,
                    border: Border(
                      top: BorderSide(
                        color: Color(0xffefefef).withOpacity(0.7),
                        width: setWidth(1),
                      ),
                    ),
                  ),
                  padding: EdgeInsets.symmetric(horizontal: setWidth(20)),
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Image.asset(
                        'assets/images/announcement_image.png',
                        width: setWidth(40),
                        height: setWidth(40),
                        fit: BoxFit.cover,
                      ),
                      SizedBox(
                        width: setWidth(16),
                      ),
                      Expanded(
                        child: Text(
                          '县委常委被调查：对我好一点，我要出去当县委书记',
                          style: TextStyle(
                            color: Color(0xff666666),
                            fontSize: 14,
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                */
  }

  umpDeco({url, model}) {
    if (url == '3') {
      if (model['icon_name'] == '本地生活') {
      } else {
        logic.getDecoData(model['linktarget']);
        return;
      }
    }
    if (url == '26') {
      logic.getCouponOrToCouponGoodsList(couponModel: model);
      return;
    }
    jump(url: url, model: model);
  }

  // 券
  Widget _discountCouponWidget({
    List couponList,
    int col = 1,
    dynamic params,
  }) {
    print("colcolcolcolc=$col");

    if (couponList.length == 0) {
      return SizedBox();
    }

    if (col == 2) {
      return Container(
        width: 750.w,
        padding: EdgeInsets.only(
          left: setWidth(10),
          top: setWidth(22),
          right: setWidth(20),
          // bottom: setWidth(28),
        ),
        color: Colors.white,
        child: Wrap(
          // mainAxisAlignment: MainAxisAlignment.spaceBetween,
          alignment: WrapAlignment.spaceBetween,
          children: couponList
              .asMap()
              .map(
                (index, model) => MapEntry(
                    index,
                    GestureDetector(
                      onTap: () {
                        print('领券点击事件！！！');

                        if (model['relation'] == 0) {
                          if (model['stock_qty'] > 0) {
                            var params = {
                              'use_platform': 2,
                              'coupon_num_id': model['series'].toString(),
                              'usr_num_id': SpUtil.getInt('empeNumId'),
                              'access_token': SpUtil.getString('token'),
                              'qsource': 301,
                              'relation_indate': "永久有效",
                              'user_num_id': SpUtil.getInt('empeNumId'),
                            };
                            Api.getCoupon(params).listen((event) {
                              if (event['code'] == 0) {
                                toast('领券成功');
                                model['relation'] = 1;
                                setState(() {});
                              }
                            });
                          } else {
                            toast('库存不足');
                          }
                        } else {
                          if (model['use_begin_date'] != '' &&
                              model['use_begin_end'] != '' &&
                              model['use_begin_date'] != null &&
                              model['use_begin_end'] != null) {
                            var startDate =
                                DateTime.tryParse(model['use_begin_date']);
                            var endDate =
                                DateTime.tryParse(model['use_begin_end']);
                            var disable =
                                (DateTime.now().isBefore(startDate)) ||
                                    (DateTime.now().isAfter(endDate));
                            if (disable) {
                              toast('未到优惠券使用时间');
                              return false;
                            }
                          }
                          Get.toNamed(RouteConfig.couponGoodsList, arguments: {
                            'coupon_id': model['series'],
                          });
                        }
                      },
                      child: Stack(
                        children: [
                          Container(
                            width: 350.w,
                            margin: EdgeInsets.only(bottom: 20.w),
                            child: Row(
                              children: [
                                Container(
                                  width: setWidth(288),
                                  height: setWidth(160),
                                  decoration: BoxDecoration(
                                    color: hexToColor(params['coupon1']),
                                    borderRadius: BorderRadius.only(
                                      topLeft: Radius.circular(setWidth(10)),
                                      bottomLeft: Radius.circular(setWidth(10)),
                                    ),
                                  ),
                                  padding: EdgeInsets.only(
                                    left: setWidth(28),
                                  ),
                                  child: Column(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    children: [
                                      model['coupontype'] == '0'
                                          ? (Text.rich(
                                              TextSpan(
                                                children: [
                                                  TextSpan(
                                                    text:
                                                        '${double.parse((model['face_value'] / 10).toStringAsFixed(2)).toString().replaceAll('.00', '').replaceAll('.0', '')}',
                                                    style: TextStyle(
                                                      color: hexToColor(
                                                          params['coupon2']),
                                                      fontSize: 28,
                                                      fontWeight:
                                                          FontWeight.bold,
                                                    ),
                                                  ),
                                                  TextSpan(
                                                    text: '折',
                                                    style: TextStyle(
                                                      color: hexToColor(
                                                          params['coupon2']),
                                                      fontSize: 16,
                                                    ),
                                                  ),
                                                ],
                                              ),
                                            ))
                                          : model['coupontype'] == '1'
                                              ? (Text.rich(
                                                  TextSpan(
                                                    children: [
                                                      TextSpan(
                                                        text: '¥',
                                                        style: TextStyle(
                                                          color: hexToColor(
                                                              params[
                                                                  'coupon2']),
                                                          fontSize: 16,
                                                        ),
                                                      ),
                                                      TextSpan(
                                                        text:
                                                            model['face_value']
                                                                .toString()
                                                                .replaceAll(
                                                                    '.0', ''),
                                                        style: TextStyle(
                                                          color: hexToColor(
                                                              params[
                                                                  'coupon2']),
                                                          fontSize: 28,
                                                          fontWeight:
                                                              FontWeight.bold,
                                                        ),
                                                      ),
                                                    ],
                                                  ),
                                                ))
                                              : (Text.rich(
                                                  TextSpan(
                                                    children: [
                                                      TextSpan(
                                                        text: '免邮',
                                                        style: TextStyle(
                                                          color: hexToColor(
                                                              params[
                                                                  'coupon2']),
                                                          fontSize: 32,
                                                          fontWeight:
                                                              FontWeight.bold,
                                                        ),
                                                      ),
                                                    ],
                                                  ),
                                                )),
                                      SizedBox(height: 2),
                                      if (model['least_cost'] == 0)
                                        Text(
                                          "无门槛",
                                          style: TextStyle(
                                              color:
                                                  hexToColor(params['coupon2']),
                                              fontSize: 12),
                                        ),
                                      if (model['least_cost'] != 0)
                                        RichText(
                                          maxLines: 1,
                                          text: TextSpan(
                                            children: [
                                              TextSpan(
                                                text: '满',
                                                style: TextStyle(
                                                  color: hexToColor(
                                                      params['coupon2']),
                                                  fontSize: 12,
                                                ),
                                              ),
                                              TextSpan(
                                                text: model['least_cost']
                                                    .toString()
                                                    .replaceAll('.0', ''),
                                                style: TextStyle(
                                                  color: hexToColor(
                                                      params['coupon2']),
                                                  fontSize: 13,
                                                ),
                                              ),
                                              TextSpan(
                                                text: '元使用',
                                                style: TextStyle(
                                                  color: hexToColor(
                                                      params['coupon2']),
                                                  fontSize: 12,
                                                ),
                                              )
                                            ],
                                          ),
                                        ),
                                      SizedBox(height: 2),
                                      if (model['fixed_term'] == null)
                                        Container(
                                          width: 300.w,
                                          child: Text(
                                            '有效期：${DateFormat('yyyy.MM.dd').format(DateTime.parse(model['use_begin_date']))} - ${DateFormat('yyyy.MM.dd').format(DateTime.parse(model['use_begin_end']))}',
                                            maxLines: 1,
                                            style: TextStyle(
                                              color:
                                                  hexToColor(params['coupon2']),
                                              fontSize: 12,
                                            ),
                                            overflow: TextOverflow.ellipsis,
                                          ),
                                        ),
                                      if (model['fixed_term'] != null)
                                        Text(
                                          '有效期：自领券${model["fixed_term"]}日内',
                                          maxLines: 1,
                                          style: TextStyle(
                                            color:
                                                hexToColor(params['coupon2']),
                                            fontSize: 12,
                                          ),
                                        ),
                                      SizedBox(
                                        height: setWidth(5),
                                      ),
                                    ],
                                  ),
                                ),
                                Container(
                                  width: setWidth(60),
                                  height: setWidth(160),
                                  padding: EdgeInsets.symmetric(
                                      horizontal: setWidth(20)),
                                  decoration: BoxDecoration(
                                    color: hexToColor(params['coupon6']),
                                    borderRadius: BorderRadius.only(
                                      topRight: Radius.circular(setWidth(10)),
                                      bottomRight:
                                          Radius.circular(setWidth(10)),
                                    ),
                                  ),
                                  alignment: Alignment.center,
                                  child: Text(
                                    model['relation'] == 0 ? '立即领取' : '去使用',
                                    style: TextStyle(
                                      color: hexToColor(params['coupon7']),
                                      fontSize: 11,
                                    ),
                                  ),
                                ),
                              ],
                            ),
                          ),
                          Positioned(
                            left: setWidth(278),
                            top: -setWidth(10),
                            child: Container(
                              width: setWidth(20),
                              height: setWidth(20),
                              decoration: BoxDecoration(
                                color: Color(0xffEFF0F3),
                                borderRadius:
                                    BorderRadius.circular(setWidth(20)),
                              ),
                            ),
                          ),
                          Positioned(
                            left: setWidth(278),
                            top: setWidth(150),
                            child: Container(
                              width: setWidth(20),
                              height: setWidth(20),
                              decoration: BoxDecoration(
                                color: Color(0xffEFF0F3),
                                borderRadius:
                                    BorderRadius.circular(setWidth(20)),
                              ),
                            ),
                          ),
                        ],
                      ),
                    )),
              )
              .values
              .toList(),
        ),
      );
    }

    return Container(
      padding: EdgeInsets.only(
        left: setWidth(20),
        right: setWidth(20),
        bottom: setWidth(20),
      ),
      color: Colors.white,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: couponList
            .asMap()
            .map((index, model) {
              return MapEntry(
                index,
                Padding(
                  padding: EdgeInsets.only(top: setWidth(20)),
                  child: Container(
                    decoration: BoxDecoration(
                      color: hexToColor(params['coupon1']),
                      borderRadius: BorderRadius.circular(setWidth(14)),
                    ),
                    height: setWidth(160),
                    child: Stack(
                      children: [
                        Row(
                          children: [
                            Container(
                              width: setWidth(236),
                              padding: EdgeInsets.symmetric(
                                  horizontal: setWidth(10)),
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  model['coupontype'] == '0'
                                      ? (Text.rich(
                                          TextSpan(
                                            children: [
                                              TextSpan(
                                                text:
                                                    '${double.parse((model['face_value'] / 10).toStringAsFixed(2)).toString().replaceAll('.00', '').replaceAll('.0', '')}',
                                                style: TextStyle(
                                                  color: hexToColor(
                                                      params['coupon2']),
                                                  fontSize: 28,
                                                  fontWeight: FontWeight.bold,
                                                ),
                                              ),
                                              TextSpan(
                                                text: '折',
                                                style: TextStyle(
                                                  color: hexToColor(
                                                      params['coupon2']),
                                                  fontSize: 16,
                                                ),
                                              ),
                                            ],
                                          ),
                                        ))
                                      : model['coupontype'] == '1'
                                          ? (Text.rich(
                                              TextSpan(
                                                children: [
                                                  TextSpan(
                                                    text: '¥',
                                                    style: TextStyle(
                                                      color: hexToColor(
                                                          params['coupon2']),
                                                      fontSize: 16,
                                                    ),
                                                  ),
                                                  TextSpan(
                                                    text: model['face_value']
                                                        .toString()
                                                        .replaceAll('.0', ''),
                                                    style: TextStyle(
                                                      color: hexToColor(
                                                          params['coupon2']),
                                                      fontSize: 28,
                                                      fontWeight:
                                                          FontWeight.bold,
                                                    ),
                                                  ),
                                                ],
                                              ),
                                            ))
                                          : (Text.rich(
                                              TextSpan(
                                                children: [
                                                  TextSpan(
                                                    text: '免邮',
                                                    style: TextStyle(
                                                      color: hexToColor(
                                                          params['coupon2']),
                                                      fontSize: 32,
                                                      fontWeight:
                                                          FontWeight.bold,
                                                    ),
                                                  ),
                                                ],
                                              ),
                                            )),
                                  SizedBox(height: 5),
                                  if (model['least_cost'] == 0)
                                    Text(
                                      "无门槛",
                                      style: TextStyle(
                                          color: hexToColor(params['coupon2']),
                                          fontSize: 12),
                                    ),
                                  if (model['least_cost'] != 0)
                                    RichText(
                                      maxLines: 1,
                                      text: TextSpan(
                                        children: [
                                          TextSpan(
                                            text: '满',
                                            style: TextStyle(
                                              color:
                                                  hexToColor(params['coupon2']),
                                              fontSize: 12,
                                            ),
                                          ),
                                          TextSpan(
                                            text: model['least_cost']
                                                .toString()
                                                .replaceAll('.0', ''),
                                            style: TextStyle(
                                              color:
                                                  hexToColor(params['coupon2']),
                                              fontSize: 13,
                                            ),
                                          ),
                                          TextSpan(
                                            text: '元使用',
                                            style: TextStyle(
                                              color:
                                                  hexToColor(params['coupon2']),
                                              fontSize: 12,
                                            ),
                                          )
                                        ],
                                      ),
                                    ),
                                ],
                              ),
                            ),
                            Container(
                              width: setWidth(474),
                              padding: EdgeInsets.symmetric(
                                  horizontal: setWidth(15)),
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  Text(
                                    // '${model['least_cost']}元代金券',
                                    '${model['title']}',
                                    style: TextStyle(
                                      color: hexToColor(params['coupon5']),
                                      fontSize: 12,
                                    ),
                                  ),
                                  if (model['fixed_term'] == null)
                                    Text(
                                      '有效期：${DateFormat('yyyy.MM.dd').format(DateTime.parse(model['use_begin_date']))} - ${DateFormat('yyyy.MM.dd').format(DateTime.parse(model['use_begin_end']))}',
                                      maxLines: 1,
                                      style: TextStyle(
                                        color: hexToColor(params['coupon5']),
                                        fontSize: 12,
                                      ),
                                    ),
                                  if (model['fixed_term'] != null)
                                    Text(
                                      '有效期：自领券${model["fixed_term"]}日内',
                                      maxLines: 1,
                                      style: TextStyle(
                                        color: hexToColor(params['coupon5']),
                                        fontSize: 12,
                                      ),
                                    ),
                                  SizedBox(height: 5),
                                  GestureDetector(
                                    onTap: () {
                                      print('领券点击事件！！！');

                                      if (model['relation'] == 0) {
                                        if (model['stock_qty'] > 0) {
                                          var params = {
                                            'use_platform': 2,
                                            'coupon_num_id':
                                                model['series'].toString(),
                                            'usr_num_id':
                                                SpUtil.getInt('empeNumId'),
                                            'access_token':
                                                SpUtil.getString('token'),
                                            'qsource': 301,
                                            'relation_indate': "永久有效",
                                            'user_num_id':
                                                SpUtil.getInt('empeNumId'),
                                          };
                                          Api.getCoupon(params).listen((event) {
                                            if (event['code'] == 0) {
                                              toast('领券成功');
                                              model['relation'] = 1;
                                              setState(() {});
                                            }
                                          });
                                        } else {
                                          toast('库存不足');
                                        }
                                      } else {
                                        if (model['use_begin_date'] != '' &&
                                            model['use_begin_end'] != '' &&
                                            model['use_begin_date'] != null &&
                                            model['use_begin_end'] != null) {
                                          var startDate = DateTime.tryParse(
                                              model['use_begin_date']);
                                          var endDate = DateTime.tryParse(
                                              model['use_begin_end']);
                                          var disable = (DateTime.now()
                                                  .isBefore(startDate)) ||
                                              (DateTime.now().isAfter(endDate));
                                          if (disable) {
                                            toast('未到优惠券使用时间');
                                            return false;
                                          }
                                        }
                                        Get.toNamed(RouteConfig.couponGoodsList,
                                            arguments: {
                                              'coupon_id': model['series'],
                                            });
                                      }
                                    },
                                    behavior: HitTestBehavior.opaque,
                                    child: Container(
                                      padding: EdgeInsets.only(
                                        left: setWidth(10),
                                        right: setWidth(10),
                                        bottom: setWidth(2),
                                      ),
                                      decoration: BoxDecoration(
                                        color: hexToColor(params['coupon6']),
                                        borderRadius:
                                            BorderRadius.circular(setWidth(6)),
                                      ),
                                      child: Text(
                                        model['relation'] == 0 ? '立即领取' : '去使用',
                                        style: TextStyle(
                                          color: hexToColor(params['coupon7']),
                                          fontSize: 13,
                                        ),
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                            ),
                          ],
                        ),
                        Positioned(
                          left: setWidth(226),
                          top: -setWidth(10),
                          child: Container(
                            width: setWidth(20),
                            height: setWidth(20),
                            decoration: BoxDecoration(
                              color: Color(0xffEFF0F3),
                              borderRadius: BorderRadius.circular(setWidth(20)),
                            ),
                          ),
                        ),
                        Positioned(
                          left: setWidth(226),
                          top: setWidth(150),
                          child: Container(
                            width: setWidth(20),
                            height: setWidth(20),
                            decoration: BoxDecoration(
                              color: Color(0xffEFF0F3),
                              borderRadius: BorderRadius.circular(setWidth(20)),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              );
            })
            .values
            .toList(),
      ),
    );
  }
}
